<?php

/**
 * EmsMenuOption form.
 *
 * @package    ems1
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class EmsMenuOptionForm extends BaseEmsMenuOptionForm
{
    public function configure()
    {
        unset ($this['created_at'], $this['updated_at'], $this['menu_id'], $this['is_enabled']);

        $this->validatorSchema['title']->setOption('required', false);
        $this->validatorSchema['title']->setOption('trim', true);
        $this->validatorSchema['title']->setMessage('max_length', 'El nombre "%value%" excede el máximo de caracteres (%max_length% max).');

        $this->widgetSchema->setHelp('link','Indique una URL de la forma: http://www.ejemplo.com');

        $this->validatorSchema['link'] = new sfValidatorUrl(
                array(
                    'required' => false,
                    'trim'     => true,
                    'max_length' => 255,
                ),array(
                    'max_length'=> 'La dirección excede el máximo de caracteres (%max_length% max).',
                    'invalid'   => 'La dirección no es de la foma válida.'
                ));

        $this->widgetSchema['is_local'] = new sfWidgetFormChoice(array(
            'choices'  => Doctrine_Core::getTable('EmsMenuOption')->getBooleanOptions(),
            'multiple' => false,
            'expanded' => true,
        ));

        $this->validatorSchema['is_local'] = new sfValidatorChoice(array(
            'choices' => array_keys(Doctrine_Core::getTable('EmsMenuOption')->getBooleanOptions()),
        ));

        $this->widgetSchema['section_id']->setOption(
                    'renderer_class',
                    'sfWidgetFormDoctrineJQueryAutocompleter'
                );
        
        $context = sfContext::getInstance();

        $this->widgetSchema['section_id']->setOption('renderer_options',
                array(
                    'model' => 'EmsSection',
                    'url'   => $context->getController()->genUrl('element_getsections'),
                    'config' => '{ limit: 20, extraParams: { portal_id:'.$this->getOption('portal_id').'}}'
                ));

        if ($this->object->exists())
        {
            $this->widgetSchema['is_enabled'] = new sfWidgetFormInputCheckbox(array('label' => 'Habilitar'));
            $this->validatorSchema['is_enabled'] = new sfValidatorBoolean();
        }

        $this->widgetSchema->setLabels(array(
                'title'      => 'Nombre',
                'link'       => 'URL',
                'section_id' => 'Sección',
                'is_local'   => 'Tipo de opción'
            ));
    }
}
